package com.platform.controller;

import java.util.List;
import java.util.Map;

import com.platform.utils.EmojiUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.platform.entity.PostsCommentEntity;
import com.platform.service.PostsCommentService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;

/**
 * 帖子评论表Controller
 *
 * @author czj
 * @email 729618941@qq.com
 * @date 2018-11-03 11:24:16
 */
@RestController
@RequestMapping("postscomment")
public class PostsCommentController {
    @Autowired
    private PostsCommentService postsCommentService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("postscomment:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<PostsCommentEntity> postsCommentList = postsCommentService.queryList(query);
        if (postsCommentList.size() > 0) {
            for (PostsCommentEntity postsCommentEntity : postsCommentList) {
                postsCommentEntity.setContentDesc(EmojiUtils.emojiRecovery2(postsCommentEntity.getContentDesc()));
            }
        }
        int total = postsCommentService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(postsCommentList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("postscomment:info")
    public R info(@PathVariable("id") Integer id) {
        PostsCommentEntity postsComment = postsCommentService.queryObject(id);

        return R.ok().put("postsComment", postsComment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("postscomment:save")
    public R save(@RequestBody PostsCommentEntity postsComment) {
        postsCommentService.save(postsComment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("postscomment:update")
    public R update(@RequestBody PostsCommentEntity postsComment) {
        postsCommentService.update(postsComment);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("postscomment:delete")
    public R delete(@RequestBody Integer[] ids) {
//
        for (int id : ids) {
            PostsCommentEntity postsComment = postsCommentService.queryObject(id);
            postsComment.setStatus(0);
            postsCommentService.update(postsComment);
        }

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<PostsCommentEntity> list = postsCommentService.queryList(params);

        return R.ok().put("list", list);
    }
}
